package com.turing.usdtpay.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.app.ActivityCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.turing.usdtpay.R;
import com.turing.usdtpay.base.BaseActivity;
import com.turing.usdtpay.entity.OrderInfoData;
import com.turing.usdtpay.http.ApiUrl;
import com.turing.usdtpay.mvp.contract.OrderInfoContract;
import com.turing.usdtpay.mvp.dialog.PhotoDialog;
import com.turing.usdtpay.mvp.presenter.OrderInfoPresenter;
import com.turing.usdtpay.mvp.view.BaseTitleView;
import com.turing.usdtpay.utils.FormatUtils;
import com.turing.usdtpay.utils.LogUtils;
import com.turing.usdtpay.utils.PhotoUtils;
import com.turing.usdtpay.utils.QRCodeUtil;
import com.turing.usdtpay.utils.ToastUtils;

import java.io.File;
import java.io.Serializable;

/**
 * @作者：JAY
 * @创建时间：2019/10/20 23:46
 * @描述：
 **/
public class OrderPayActivity extends Activity implements View.OnClickListener ,OrderInfoContract.View {

    private BaseTitleView mTitle;
    private ImageView mPhoto;
    private String mOrder;
    private OrderInfoContract.Present mPresent;
    private TextView mOrderTv,mState,mProportion,mUsdt,mTotal,mCny,mName,mBank,mBankId;
    private double mRate;
    private String mUrl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_pay);
        initView();
        initTitle();
        setPresenter(new OrderInfoPresenter(this));
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        OrderInfoData data = (OrderInfoData) intent.getSerializableExtra("data");
        if (data != null){
            mOrder = data.getOrder();
            mOrderTv.setText(data.getOrder());
            if (data.getStatus() == 0){
                mState.setText("待付款");
            }else if (data.getStatus() == 1){
                mState.setText("待收款");
            }else if (data.getStatus() == 2){
                mState.setText("已完成");
            }else if (data.getStatus() == 3){
                mState.setText("已取消");
            }
            mRate = (double) data.getMoney_change_usdt()/100;
            mProportion.setText(FormatUtils.NoumberFromat2(mRate)+" CNY/USDT");
            mTotal.setText(FormatUtils.NoumberFromat2(((double) data.getMoney()/100))+" CNY");
            mUsdt.setText(FormatUtils.NoumberFromat8(((double) data.getMoney()/100)/mRate)+" USDT");

            mCny.setText(FormatUtils.NoumberFromat2(((double)data.getMoney()/100))+"");
            mName.setText(data.getPay_bank_name());
            mBank.setText(data.getPay_bank());
            mBankId.setText(data.getPay_bank_id());

            if (!TextUtils.isEmpty(mOrder)){
                mUrl = ApiUrl.API_DOWNLOAD_IMG + mOrder+".jpg";
                Picasso.get().load(mUrl).into(mPhoto);
            }
        }

    }

    private void initTitle() {
        mTitle.setLeftShow(true);
        mTitle.setLeftButtonListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitle.setTitle("已完成订单");
    }

    private void initView() {
        mTitle = (BaseTitleView) findViewById(R.id.title);
        mPhoto = (ImageView) findViewById(R.id.iv_photo);
        mOrderTv = (TextView) findViewById(R.id.tv_order);
        mState = (TextView) findViewById(R.id.tv_state);
        mProportion = (TextView) findViewById(R.id.tv_proportion);
        mUsdt = (TextView) findViewById(R.id.tv_usdt);
        mTotal = (TextView) findViewById(R.id.tv_total);
        mCny = (TextView) findViewById(R.id.tv_cny);
        mName = (TextView) findViewById(R.id.tv_name);
        mBank = (TextView) findViewById(R.id.tv_bank_name);
        mBankId = (TextView) findViewById(R.id.tv_bank_id);

        mPhoto.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == mPhoto.getId()){
            PhotoDialog dialog = new PhotoDialog(this);
            dialog.show();
            dialog.setUrl(mUrl);
        }
    }


    @Override
    public void onSuccess(OrderInfoData data) {


    }

    @Override
    public void uploadSuccess(String url) {
    }

    @Override
    public void getSuccess() {

    }

    @Override
    public void paySuccess() {

    }

    @Override
    public void cancelSuccess() {
        ToastUtils.showNormolToast(this,"取消成功");
    }

    @Override
    public void onFail(String msg) {
        ToastUtils.showNormolToast(this,msg);
    }

    @Override
    public void onProgress(int progress) {

    }

    @Override
    public void setPresenter(OrderInfoContract.Present presenter) {
        mPresent = presenter;
    }
}
